package com.lwb.ztx.main.model;

import com.lwb.ztx.api.Api;
import com.lwb.ztx.bean.ProfileBean;
import com.lwb.ztx.utils.LogUtils;
import com.lwb.ztx.utils.OkHttpUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/5/28.
 */
public class LoadingModelImpl implements LoadingModel {
    private OnLoadingFinishListener listener;

    public LoadingModelImpl(OnLoadingFinishListener listener) {
        this.listener = listener;
    }

    @Override
    public void loadTotalProfile() {
        OkHttpUtils.ResultCallback<String> loadNewsCallback = new OkHttpUtils.ResultCallback<String>() {
            @Override
            public void onSuccess(String response) {
                List<ProfileBean> profileBeanList = LoadingJsonUtils.readJsonLoadingBeans(response);
                LogUtils.i(profileBeanList.toString());
                listener.onSuccess(profileBeanList);
            }

            @Override
            public void onFailure(Exception e) {
                listener.onFailure();
            }
        };
        OkHttpUtils.get(Api.getTotlProfileUrl(), loadNewsCallback);
    }

    public interface OnLoadingFinishListener{
        void onSuccess(List<ProfileBean> profileBeanList);
        void onFailure();
    }
}
